package com.ruoyi.energy.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.energy.domain.NyEnteriseLoad;
import com.ruoyi.energy.domain.NyTrans;
import com.ruoyi.energy.domain.NyTransCheck;
import com.ruoyi.energy.domain.NyTransLoad;
import com.ruoyi.energy.service.INyTransCheckService;
import com.ruoyi.energy.service.INyTransLoadService;
import com.ruoyi.energy.service.INyTransPartArrsService;
import com.ruoyi.energy.service.INyTransService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 变压器监测Controller
 *
 * @author cjie
 * @date 2021-10-11
 */
@Api(tags = " 变压器监测微信接口-废弃")
@RestController
@RequestMapping("/nyTransCheckWX")
public class NyTransCheckWXController extends BaseController {
    @Autowired
    private INyTransCheckService nyTransCheckService;
    @Autowired
    private INyTransLoadService nyTransLoadService;

    @Autowired
    private INyTransService nyTransService;

    @Autowired
    private INyTransPartArrsService nyTransPartArrsService;

    /**
     * 变压器列表
     */
    @ApiOperation(value="箱变列表-根据园区查询", notes="箱变列表-根据园区查询")
    @PreAuthorize(hasPermi = "energy:nyTransCheck:list")
    @GetMapping("/list")
    public TableDataInfo list(NyTrans nyTrans) {
        startPage();
        List<NyTrans> list = nyTransService.selectNyTransList(nyTrans);
        return getDataTable(list);
    }

    /**
     * 根据transId、checkTime查询箱变监测
     */
    @ApiOperation(value="根据transId、checkTime查询箱变监测", notes="根据transId、checkTime查询箱变监测")
    @PreAuthorize(hasPermi = "energy:nyTransCheck:query")
    @PostMapping(value = "/getTransLoad")
    public AjaxResult getTransLoad(@RequestBody NyTransLoad nyTransLoad) {
        return AjaxResult.success(nyTransLoadService.selectNyTransLoadByentity(nyTransLoad));
    }

    /**
     * 保存变压器监测
     */
    @ApiOperation(value="箱变-监测抄录-提交", notes="箱变-监测抄录-提交")
    @PreAuthorize(hasPermi = "energy:nyTrans:edit")
    @PostMapping(value = "/saveTransLoad")
    public AjaxResult edit(@RequestBody NyTransLoad nyTransLoad) {
        return toAjax(nyTransLoadService.addAndUpdateTransLoad(nyTransLoad));
    }

    //箱变-空开列表
    @ApiOperation(value="箱变-空开单个抄录-选择列表", notes="箱变-空开单个抄录-选择列表")
    @PreAuthorize(hasPermi = "energy:nyTrans:edit")
    @GetMapping(value = "/airs/{transId}")
    public AjaxResult getAirList(@PathVariable("transId") Long id) {
        return AjaxResult.success(nyTransPartArrsService.getAirListByTransId(id));
    }

    //箱变-空开-企业列表
    @ApiOperation(value="根据空开swiftId、checkTime查询企业空开监测", notes="根据空开Id、checkTime查询企业空开监测")
    @PreAuthorize(hasPermi = "energy:nyTrans:edit")
    @PostMapping(value = "/getNyEnteriseLoad")
    public AjaxResult getAirBySwiftId(@RequestBody NyTransCheck nyTransCheck) {
        return AjaxResult.success(nyTransPartArrsService.getNyEnteriseLoadsAir(nyTransCheck));
    }

    //箱变-空开-企业监测-提交
    @ApiOperation(value="箱变-空开-企业监测-提交", notes="箱变-空开-企业监测-提交")
    @PostMapping(value = "/air/save")
    public AjaxResult saveAirCheckInfo(@RequestBody List<NyEnteriseLoad> map) {
        //return toAjax(nyTransCheckService.saveWXNyTransCheck(wxNyTransDetial));
        return toAjax(nyTransCheckService.batchInsertNyEnteriseLoad(map));
    }

    /* transId,checkTime
    * */
    @ApiOperation(value="箱变-空开-批量抄录", notes="箱变-空开-批量抄录")
    @PreAuthorize(hasPermi = "energy:nyTrans:query")
    @PostMapping(value = "/trans/gen")
    public AjaxResult genWXCheckInfo(@RequestBody NyTransCheck nyTransCheck) {
        return AjaxResult.success(nyTransPartArrsService.genNyEnteriseLoadsTrans(nyTransCheck));
    }

    @ApiOperation(value="箱变-空开-批量抄录提交", notes="箱变-空开-批量抄录提交")
    @PostMapping(value = "/wx/save")
    public AjaxResult saveWXCheckInfo(@RequestBody List<NyEnteriseLoad> map) {
        return toAjax(nyTransCheckService.batchInsertNyEnteriseLoad(map));
    }

    @ApiOperation(value="箱变-设备监测-月-总负荷", notes="箱变-设备监测-月-总负荷")
    @PreAuthorize(hasPermi = "energy:nyTrans:query")
    @Log(title = "历史负荷")
    @GetMapping(value = "/wx/month")
    public TableDataInfo getTransCheckInfo(NyTransLoad nyTransLoad) {
        List<NyTransLoad> list = nyTransLoadService.selectNyTransLoadList(nyTransLoad);
        return getDataTable(list);
    }

    @ApiOperation(value="箱变-设备监测-天-企业负荷", notes="箱变-设备监测-天-企业负荷")
    @Log(title = "企业负荷")
    @GetMapping(value = "/wx/list")
    public TableDataInfo getTransCheckInfo1(NyTransCheck nyTransCheck) {
        List<NyTransCheck> list = nyTransCheckService.selectNyTransCheckList(nyTransCheck);
        return getDataTable(list);
    }

}
